﻿using System.Web.Script.Serialization;

namespace ScrumPilot.Helpers
{
    public static class JSONHelper
    {

        public static string ToJSON(this object obj)
        {
            var serializer = new JavaScriptSerializer();
            return serializer.Serialize(obj);
        }

        public static string ToJSON(this object obj, int depth)
        {
            var serializer = new JavaScriptSerializer { RecursionLimit = depth };
            return serializer.Serialize(obj);
        }

        public static int[] FromJSON(this string obj)
        {
            var serializer = new JavaScriptSerializer();
            return serializer.Deserialize<int[]>(obj);
        }

        public static string[] FromJSONToString(this string obj)
        {
            var serializer = new JavaScriptSerializer();
            return serializer.Deserialize<string[]>(obj);
        }
    }
}